package com.base.framework.common.response;

/**
 * { "head":{"success":"true/false",message:"aaa"}, "body":{"xxx":"xxxx","xxx":"xxxx"}}
 * 
 * 返回数据格式
 */
public class ActionResponse<E> {

	/** 结果头部信息 */
	private Head head = new Head();

	private Body body = new Body();


	public ActionResponse(boolean success, E e) {
		head.setSuccess(success);
		body.setResult(e);
	}


	public ActionResponse() {

	}
	public Head getHead() {
		return head;
	}

	public E getBody() {
		return body.getResult();
	}

	public void success(E e) {
		this.head.setSuccess(Boolean.TRUE);
		this.body.setResult(e);
	}


	/**
	 * 用户参数验证失败.
	 * <p>
	 * <p>
	 * 
	 * @Title fail
	 * @param msg
	 * @return void 返回类型
	 */
	public void failMessage(String msg) {
		this.head.setSuccess(Boolean.FALSE);
		this.head.setMessage(msg);
	}

	/**
	 * 接口返回状态. 前端根据头部信息来判断当前的结果状态.
	 */
	private class Head {

		private boolean success;
		private String message;

		public boolean getSuccess() {
			return success;
		}

		public void setSuccess(boolean success) {
			this.success = success;
		}


		public String getMessage() {
			return message;
		}

		public void setMessage(String message) {
			this.message = message;
		}
	}

	/**
	 * 接口返回数据. 页面显示的数据,或者是错误信息的详细.
	 */
	private class Body {

		private E result;

		public E getResult() {
			return result;
		}

		public void setResult(E result) {
			this.result = result;
		}
	}
}
